package stores

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// LSTORE Store long into local variable
type LSTORE struct{ base.Index8Instruction }

func (ls *LSTORE) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, ls.Index)
}

type LSTORE_0 struct{ base.NoOperandsInstruction }

func (ls *LSTORE_0) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 0)
}

type LSTORE_1 struct{ base.NoOperandsInstruction }

func (ls *LSTORE_1) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 1)
}

type LSTORE_2 struct{ base.NoOperandsInstruction }

func (ls *LSTORE_2) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 2)
}

type LSTORE_3 struct{ base.NoOperandsInstruction }

func (ls *LSTORE_3) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 3)
}

func _lstore(jFrame *rtda.JFrame, index uint) {
	val := jFrame.OperandStack().PopLong()
	jFrame.LocalVars().SetLong(index, val)
}
